<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>基于爬虫的商品监控与分析系统</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<!-- basic styles -->
		<link href="assets/css/bootstrap.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="assets/css/font-awesome.min.css" />

		<!--[if IE 7]>
		  <link rel="stylesheet" href="assets/css/font-awesome-ie7.min.css" />
		<![endif]-->

		<!-- page specific plugin styles -->


		<!-- ace styles -->

		<link rel="stylesheet" href="assets/css/ace.min.css" />
		<link rel="stylesheet" href="assets/css/ace-rtl.min.css" />
		<link rel="stylesheet" href="assets/css/ace-skins.min.css" />
		<link rel="stylesheet" href="assets/css/bootstrap-table.css" />

		<!--[if lte IE 8]>
		  <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
		<![endif]-->

		<!-- inline styles related to this page -->

		<!-- ace settings handler -->

		<script src="assets/js/ace-extra.min.js"></script>
        <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script>

		<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->

		<!--[if lt IE 9]>
		<script src="assets/js/html5shiv.js"></script>
		<script src="assets/js/respond.min.js"></script>
		<![endif]-->
	</head>

	<body>
		<div class="navbar navbar-default" id="navbar">
			<script type="text/javascript">
				try{ace.settings.check('navbar' , 'fixed')}catch(e){}
			</script>

			<div class="navbar-container" id="navbar-container">
				<div class="navbar-header pull-left">
					<a href="#" class="navbar-brand">
						<small>
							<i class="icon-leaf"></i>
							基于爬虫的商品监控与分析系统
						</small>
					</a><!-- /.brand -->
				</div><!-- /.navbar-header -->

				<div class="navbar-header pull-right" role="navigation">
					<ul class="nav ace-nav">
						<li class="light-blue">
							<a data-toggle="dropdown" href="#" class="dropdown-toggle">
								<img class="nav-user-photo" src="assets/avatars/user.jpg" alt="Jason's Photo" />
								<span class="user-info">
									<small>欢迎光临</small>
								</span>

								<i class="icon-caret-down"></i>
							</a>

							<ul class="user-menu pull-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close">
								<li>
									<a href="login.html">
										<i class="icon-off"></i>
										退出
									</a>
								</li>
							</ul>
						</li>
					</ul><!-- /.ace-nav -->
				</div><!-- /.navbar-header -->
			</div><!-- /.container -->
		</div>

		<div class="main-container" id="main-container">
			<script type="text/javascript">
				try{ace.settings.check('main-container' , 'fixed')}catch(e){}
			</script>

			<div class="main-container-inner">
				<a class="menu-toggler" id="menu-toggler" href="#">
					<span class="menu-text"></span>
				</a>

				<div class="sidebar" id="sidebar">
					<script type="text/javascript">
						try{ace.settings.check('sidebar' , 'fixed')}catch(e){}
					</script>

					<ul class="nav nav-list">
						<li>
							<a href="user.html">
								<i class="icon-edit"></i>
								<span class="menu-text"> 用户管理 </span>
							</a>
						</li>
						<li>
							<a href="crawler.html">
								<i class="icon-list-alt"></i>
								<span class="menu-text"> 数据获取 </span>
							</a>
						</li>
						<li class="active">
							<a href="goods.html" class="dropdown-toggle">
								<i class="icon-desktop"></i>
								<span class="menu-text"> 商品监控 </span>
							</a>
						</li>


						<li>
                            <a href="shop.html" class="dropdown-toggle">
                                <i class="icon-tag"></i>
                                <span class="menu-text"> 监控记录 </span>
                            </a>
                        </li>

						<li>
							<a href="store.html" class="dropdown-toggle">
								<i class="icon-list"></i>
								<span class="menu-text"> 店铺分析 </span>
							</a>
						</li>

						
					</ul><!-- /.nav-list -->

					<div class="sidebar-collapse" id="sidebar-collapse">
						<i class="icon-double-angle-left" data-icon1="icon-double-angle-left" data-icon2="icon-double-angle-right"></i>
					</div>

					<script type="text/javascript">
						try{ace.settings.check('sidebar' , 'collapsed')}catch(e){}
					</script>
				</div>

				<div class="main-content">
					<div class="breadcrumbs" id="breadcrumbs">
						<script type="text/javascript">
							try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
						</script>

						<ul class="breadcrumb">
							<li>
								<i class="icon-home home-icon"></i>
								<a href="#">首页</a>
							</li>
							<li class="active">商品监控</li>
						</ul><!-- .breadcrumb -->

					</div>

					<div class="page-content">
						<div class="page-header">
							<h1>
								商品监控
								<small>
									<i class="icon-double-angle-right"></i>
									 查看
								</small>
							</h1>
						</div><!-- /.page-header -->

						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->

								<div class="alert alert-block alert-success">
									<button type="button" class="close" data-dismiss="alert">
										<i class="icon-remove"></i>
									</button>

									<i class="icon-ok green"></i>

									可以对商品进行监控，可在监控记录中查看
								</div>
								<!-- 搜索框 -->
					            <div class="panel-body">
					                <form role="form" id="searchForm" class="form-inline">
					                    <div class="form-group"> <input type="text"
					                            class="form-control" id="keyboard" name="keyboard" placeholder="请输入商品类别">
					                    </div>
					                    <div class="form-group">
					                        <button type="button" id="searchBtn" class="btn btn-default">开始筛选</button>
					                    </div>
                                        <div class="form-group">
                                            <button type="button" id="chartBtn" class="btn btn-default">商品销售量分析</button>
                                        </div>
                                        <div class="form-group">
                                            <button type="button" id="chartBtn1" class="btn btn-default">商品销售额分析</button>
                                        </div>
					                </form>
					            </div>
					            <table id="table" style="table-layout: fixed;word-break:break-all;"></table>
								<!-- PAGE CONTENT ENDS -->
							</div><!-- /.col -->
						</div> <!-- /.row -->
					</div><!-- /.page-content -->
				</div><!-- /.main-content -->
			</div><!-- /.main-container-inner -->


            <!-- 操作图标模态框 -->
            <div class="modal fade" id="opDatanalyseModal" tabindex="-1" role="dialog" >
              <div class="modal-dialog" role="document">
                <div class="modal-content">
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel">商品分析</h4>
                  </div>
                  <div id="loading" style="height: 400px; margin: 0">
                    <div id="container" style="width:600px;height:400px;"></div>
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-danger" id="modalconfirm">确定</button>
                  </div>
                </div>
              </div>
            </div>

			<!-- 操作模态框 -->
			<div class="modal fade" id="opDataxJobRowModal" tabindex="-1" role="dialog" >
			  <div class="modal-dialog" role="document">
			    <div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			        <h4 class="modal-title" id="exampleModalLabel">警告</h4>
			      </div>
			      <div class="modal-body">
			                <strong id="warningText"></strong>
			      </div>
			      <div class="modal-footer">
			        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			        <button type="button" class="btn btn-danger" id="confirmBtn"></button>
			      </div>
			    </div>
			  </div>
			</div>
			<!-- 操作成功提示模态框 -->
			<div id="opSuccessModal" class="modal fade " tabindex="-1" role="dialog" >
			  <div class="modal-dialog modal-sm" role="document">

			    <div class="modal-content">
			        <div class="modal-header">
			            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			            <h4 class="modal-title">提示</h4>
			        </div>
			        <div class="modal-body">
			            <p style="color:green">操作成功，正在监控中...</p>
			        </div>
			    </div>
			  </div>
			</div>
			<!-- 操作失败提示模态框 -->
			<div id="opFailedModal" class="modal fade " tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
			  <div class="modal-dialog modal-sm" role="document">

			    <div class="modal-content">
			        <div class="modal-header">
			            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			            <h4 class="modal-title">提示</h4>
			        </div>
			        <div class="modal-body">
			            <p style="color:red" id="opFaildeMessage">操作失败，请勿重复监控</p>
			        </div>
			    </div>
			  </div>
			</div>

			<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
				<i class="icon-double-angle-up icon-only bigger-110"></i>
			</a>
		</div><!-- /.main-container -->

		<!-- basic scripts -->


		<!--[if !IE]> -->

		<script type="text/javascript">
			window.jQuery || document.write("<script src='assets/js/jquery-2.0.3.min.js'>"+"<"+"script>");
		</script>

		<!-- <![endif]-->

		<!--[if IE]>
<script type="text/javascript">
 window.jQuery || document.write("<script src='assets/js/jquery-1.10.2.min.js'>"+"<"+"script>");
</script>
<![endif]-->

		<script type="text/javascript">
			if("ontouchend" in document) document.write("<script src='assets/js/jquery.mobile.custom.min.js'>"+"<"+"script>");
		</script>
		<script src="assets/js/bootstrap.min.js"></script>
		<script src="assets/js/typeahead-bs2.min.js"></script>

		<!-- page specific plugin scripts -->

		<!--[if lte IE 8]>
		  <script src="assets/js/excanvas.min.js"></script>
		<![endif]-->

		<script src="assets/js/jquery-ui-1.10.3.custom.min.js"></script>
		<script src="assets/js/jquery.ui.touch-punch.min.js"></script>
		<script src="assets/js/jquery.slimscroll.min.js"></script>
		<script src="assets/js/jquery.easy-pie-chart.min.js"></script>
		<script src="assets/js/jquery.sparkline.min.js"></script>

		<!-- ace scripts -->

		<script src="assets/js/ace-elements.min.js"></script>
		<script src="assets/js/ace.min.js"></script>
		<script src="assets/js/table/bootstrap-table.js"></script>
		<script src="assets/js/table/bootstrap-table-zh-CN.js"></script>

		<!-- inline scripts related to this page -->

		<script type="text/javascript">
			var message = '';
            var myChart='';
            var data = [];
            var flag = 0;
			// 初始化表格数据
			$(function(){
                $('#table').bootstrapTable("showLoading");
				$.ajax({
					url: "http://127.0.0.1:8082/api/crawler/get_crawler_profile/",
					method: "get",
					dataType: "json",
					success: function(rs){
						message = rs.results
		                $('#table').bootstrapTable('load', message);
						$('#table').bootstrapTable('refresh');
						$('#table').bootstrapTable("hideLoading");
					},
				})
			});
			// 初始化表格
			$('#table').bootstrapTable({
				cache:false,
				clickToSelect:true,
				pageSize: 15,
				pageNumber: 1,
				pagination: true,
				columns: [{
					field: 'id',
			    	title: '编号'
			  	}, {
			    	field: 'name',
			    	title: '商品名称'
			  	}, {
			    	field: 'image',
			    	title: '商品图片'
			  	}, {
			    	field: 'address',
			    	title: '商品地址'
			  	}, {
			    	field: 'shop',
			    	title: '商品店铺'
			  	}, {
			    	field: 'keyboard',
			    	title: '商品类别'
			  	}, {
			  		field: 'commit',
			  		title: '销售量'
			  	},{
			  		field: 'count',
			  		title: '销售额',
			  		formatter:function(value,row,index){
		                return '<i class="fa fa-edit"></i> '+parseInt(row.commit)*parseInt(row.price)+'元';
		            },
			  	}, {
			    	field: 'operate',
			    	title: '商品操作',
			    	formatter:function(value,row,index){
		                return '<a  id="runDataxJob" class="btn btn-xs btn-warning"><i class="fa fa-edit"></i> 监控</a>';
		            },
		            events: {
						'click #runDataxJob': function (e, value, row, index) {
							//动态控制模态框的显示内容，为模态框的按钮动态的绑定事件，包括删除事件和执行事件，
							//这样模态框就可以复用
							$("#warningText").text("是否监控Id为： " +row.id + " 的商品");
							$("#confirmBtn").text("确认");
							$("#confirmBtn").on("click",function(){
								monitoringById(row)
							});
							$("#opDataxJobRowModal").modal();
						}
					}
			  	}],
			});
			// 搜索
			$("#searchBtn").click(function() {
                var keyboard = $("#keyboard").val();
                $('#table').bootstrapTable("showLoading");
                $.ajax({
                     type: "get",
                     url: "http://127.0.0.1:8082/api/crawler/get_crawler_profile_by_keyboard/",
                     cache: false,
                     data: {keyboard : keyboard},
                     success : function(res) {
                     	message = res.results
                        $("#table").bootstrapTable('load', message);//主要是要这种写法
						$('#table').bootstrapTable('refresh');
						$('#table').bootstrapTable("hideLoading");
                    }
                });

            });
            // 查看是否正在被被监控
			function monitoringById(row){
				$.ajax({
                     type: "get",
                     url: "http://127.0.0.1:8082/api/crawler/check_goods_by_monitoring/",
                     cache: false,
                     data: {crawler_id : row.id},
                     success : function(res) {
                     	if(res.results.length == 0){
                			$.ajax({
			                     type: "post",
			                     url: "http://127.0.0.1:8082/api/crawler/add_goods_to_monitoring/",
			                     cache: false,
			                     data: {
			                     	address : row.address,
			                     	image : row.image,
			                     	name : row.name,
			                     	shop : row.shop,
			                     	keyboard : row.keyboard,
			                     	crawler : row.id
		                     	},
			                     success : function(res) {
			                     	if(res.results == []){
			                     		$("#opDataxJobRowModal").modal('toggle');
			                     		flag = 1;
			                			$("#opFailedModal").modal();
			                     	} else {
			                     		$("#opDataxJobRowModal").modal('toggle');
			                			$("#opSuccessModal").modal();
			                     	}
			                    }
			                });
                     	} else {
                     		$("#opDataxJobRowModal").modal('toggle');
                			$("#opFailedModal").modal();
                     	}
                    }
                });
			}
            // 店铺销售量分析
            $("#chartBtn").click(function() {
                if(message == '' || message == null){
                    alert("请等待加载完再点击！")
                    return
                }
                $("#opDatanalyseModal").modal('toggle');
                var dom = document.getElementById("container");
                myChart = echarts.init(dom);
                var app = {};
                var option;
                data = [];
                for (var i=0; i<message.length;i++){
                    var simple = {value: message[i].commit, name: message[i].name}
                    data.push(simple)
                }
                option = {
                    tooltip: {
                        trigger: 'item'
                    },
                    series: [
                        {
                            name: '商品名',
                            type: 'pie',
                            radius: '40%',
                            data: data,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };

                if (option && typeof option === 'object') {
                    myChart.setOption(option);
                }
            });
            // 店铺销售额分析
            $("#chartBtn1").click(function() {
                if(message == '' || message == null){
                    alert("请等待加载完再点击！")
                    return
                }
                $("#opDatanalyseModal").modal('toggle');
                var dom = document.getElementById("container");
                myChart = echarts.init(dom);
                var app = {};
                var option;
                data = [];
                for (var i=0; i<message.length;i++){
                	var value = parseInt(message[i].commit)*parseInt(message[i].price)
                    var simple = {value: value, name: message[i].name}
                    data.push(simple)
                }
                option = {
                    tooltip: {
                        trigger: 'item'
                    },
                    series: [
                        {
                            name: '商品名',
                            type: 'pie',
                            radius: '40%',
                            data: data,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };

                if (option && typeof option === 'object') {
                    myChart.setOption(option);
                }
            });
            // 关闭模态框
            $("#modalconfirm").click(function() {
            	if(flag == 1){
            		flag = 0;
                	("#opDataxJobRowModal").modal('toggle');
            	} else {
                	$("#opDatanalyseModal").modal('toggle');
            	}
                myChart.clear();
                myChart = '';
                data = [];
            });

            $('#modal').on('hidden.bs.modal', function () {
                myChart.clear();
                myChart = '';
                data = [];
            })
		</script>
</body>
</html>

